package com.tcredit.spider.web.controller;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.tcredit.spider.web.model.User;
import com.tcredit.spider.web.service.UserService;

@RestController
public class UserController {

	protected final Logger logger = LogManager.getLogger(HelloController.class);

	@Autowired
	private UserService userService;

	/**
	 * 查询所有用户
	 */
	@RequestMapping(value = "/user/get", method = RequestMethod.GET )
	public List<User> getUser() {
		List<User> all = userService.getAll();
		return all;
	}

	/**
	 * 新增
	 */
	@RequestMapping(value = "/user/add/{name}", method = RequestMethod.GET )
	public int addUser(@PathVariable String name) {
		int id = userService.add(name);
		return id;
	}
	
	/**
	 * 修改
	 */
	@RequestMapping(value = "/user/update/{id}", method = RequestMethod.GET )
	public int updateUser(@PathVariable int id) {
		int num = userService.update(id);
		return num;
	}
	
	/**
	 * 测试回滚
	 */
	@RequestMapping(value = "/user/rollback/{id}/{name}", method = RequestMethod.GET )
	public int rollback(@PathVariable int id, @PathVariable String name) {
		int num = userService.rollback(id, name);
		return num;
	}
}
